;=================================================================================
;=========== SOME FUNCTION FOR AABBOX 
;=================================================================================
Structure AABBOX
  MinEdge.iVECTOR3
  MaxEdge.iVECTOR3
EndStructure


Procedure AABBox_Set( *box.AABBOX, xmin.f, ymin.f, zmin.f, xmax.f, ymax.f, zmax.f)
  VECTOR3_( *box\MinEdge, xmin, ymin, zmin)
  VECTOR3_( *box\MaxEdge, xmax, ymax, zmax)
EndProcedure

Procedure AABBox_Center(*center.iVECTOR3, *box.AABBOX)
  Vec3_Zero(*center)
  Vec3_Add(*center, @*box\MinEdge, @*box\MaxEdge)
  Vec3_MulF(*center, *center, 0.5)
EndProcedure

Procedure AABBox_Extend(*ext.iVECTOR3, *box.AABBOX)
  Vec3_Zero(*ext)
  Vec3_Sub(*ext, @*box\MaxEdge, @*box\MinEdge)
  Vec3_MulF(*ext, *ext, 0.5)
EndProcedure

Procedure AABBox_AddPoint( *box.AABBOX, x.f, y.f, z.f)
  If( x> *box\MaxEdge\x) : *box\MaxEdge\x=x : EndIf 
  If( y> *box\MaxEdge\y) : *box\MaxEdge\y=y : EndIf 
  If( z> *box\MaxEdge\z) : *box\MaxEdge\z=z : EndIf 

  If( x< *box\MinEdge\x) : *box\MinEdge\x=x : EndIf 
  If( y< *box\MinEdge\y) : *box\MinEdge\y=y : EndIf 
  If( z< *box\MinEdge\z) : *box\MinEdge\z=z : EndIf 
EndProcedure

Procedure.l AABBox_isPointInside( *box.AABBOX, x.f, y.f, z.f)
 If (x >= *box\MinEdge\x And x <= *box\MaxEdge\x And	y >= *box\MinEdge\y And y <= *box\Maxedge\y And z >= *box\MinEdge\z And z <= *box\MaxEdge\z)
    ProcedureReturn 1
 EndIf
 ProcedureReturn 0
EndProcedure

Procedure AABBox_xform( *out.AABBOX, *in.AABBOX, *M.iMATRIX)
		Protected c.iVECTOR3, e.iVECTOR3
		Protected absM.iMATRIX
		AABBox_Center(@c, *in)
		AABBox_Extend(@e, *in)

		Matrix_TransformVect(@c, *M )

    Matrix_Identity(@absM)
		
		absM\M[0] = Abs( *M\M[0] ) : absM\M[1] = Abs(*M\M[1]) : absM\M[2] = Abs( *M\M[2])
		absM\M[4] = Abs( *M\M[4] ) : absM\M[5] = Abs(*M\M[5]) : absM\M[6] = Abs( *M\M[6])
		absM\M[8] = Abs( *M\M[8] ) : absM\M[9] = Abs(*M\M[9]) : absM\M[10]= Abs( *M\M[10])
		Matrix_TransformVect(@e, @absM )
		
		Vec3_Sub(@*out\MinEdge , @c, @e)
		Vec3_Add(@*out\MaxEdge , @c, @e)
EndProcedure
; IDE Options = PureBasic 4.30 Beta 5 (Windows - x86)
; CursorPosition = 45
; FirstLine = 14
; Folding = --